/* 表单验证MIXIN
-------------------------- */
const FormVerifingMixin = {
  name: 'FormVerifingMixin',
  data () {
    return {
      formError: new Error('自定义表单验证出错')
    }
  },
  methods: {
    // 验证是否为空
    FormVerifyEmpty (...formCtrls) {
      const isEmpty = formCtrls.some(formCtrl => {
        if (!formCtrl.value) {
          this.$message.warning(`${formCtrl.name}不能为空`)
          this.$refs[formCtrl.ref].focus()
        }
        return !formCtrl.value
      })
      return isEmpty ? Promise.resolve([ this.formError ]) : Promise.resolve([])
    },
    // 新建表单控件
    newFormCtrl (name, ref, value = '') {
      return { name: name, ref: ref, value: value }
    }
  }
}

export default FormVerifingMixin
